package spu

import (
	"context"
	"mall/services/product/rpc/internal/mapper"
	"mall/services/product/rpc/internal/svc"
	"mall/services/product/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelSpuAttrLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelSpuAttrLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelSpuAttrLogic {
	return &DelSpuAttrLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelSpuAttrLogic) DelSpuAttr(in *pb.DelSpuAttrDTO) (*pb.EmptyObj, error) {
	// del att value
	valueMapper := mapper.NewSpuAttrValueMapper()
	delError := valueMapper.DeleteCtx(l.ctx, l.svcCtx.DBEngin, in.SpuAttrValueId)
	if delError != nil {
		return nil, delError
	}
	// return obj
	return &pb.EmptyObj{}, nil
}
